﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;

using DTO;

namespace DAO
{
    public class KhachHangDAO : DataProvider
    {
        public List<int> ThemKhachHang(List<KhachHangDTO> dskh)
        {
            List<int> dsMaKH = new List<int>();
            DataProvider dp = new DataProvider();
            SqlConnection con = dp.MoKetNoi();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "sp_ThemKhachHang";
            cmd.CommandType = CommandType.StoredProcedure;

            for (int i = 0; i < dskh.Count; i++)
            {
                cmd.Parameters.Clear();
                SqlParameter param = cmd.Parameters.Add("@HoTen", SqlDbType.NVarChar);
                param.Value = dskh[i].HoTen;
                param = cmd.Parameters.Add("@CMND", SqlDbType.VarChar);
                param.Value = dskh[i].Cmnd;
                param = cmd.Parameters.Add("@LoaiKH", SqlDbType.Int);
                param.Value = dskh[i].LoaiKH;
                param = cmd.Parameters.Add("@DiaChi", SqlDbType.NVarChar);
                param.Value = dskh[i].DiaChi;
                int makh = (int)cmd.ExecuteScalar();
                if (makh > 0)
                {
                    dsMaKH.Add(makh);
                }
            }
            
            dp.DongKetNoi(con);
            return dsMaKH;
        }
    }
}
